using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Validation;
using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;

using EntLibContrib.Validation.Validators;

namespace EntLibContrib.Validation.Tests.Validators
{
    [TestClass]
    public class CompositeRulesetValidatorFixture
    {
        [TestMethod, DeploymentItem(@"Validators\CompositeRulesetValidator.config")]
        public void ValidationResultsFromCompositeRuleSetAreAggregated()
        {
            IConfigurationSource configurationSource = ConfigurationSourceFactory.Create("CompositeRulesetValidator");
            
            Foo foo = new Foo();

            Validator validator = ValidationFactory.CreateValidatorFromConfiguration(typeof(Foo), "Composite", configurationSource);

            List<ValidationResult> vrs = new List<ValidationResult>(validator.Validate(foo));

            Assert.AreEqual(2, vrs.Count);
        }

        [TestMethod]
        public void ValidationResultsFromCompositeRuleSetWithAttributesAreAggregated()
        {
            FooWithAttributes foo = new FooWithAttributes();

            List<ValidationResult> vrs = new List<ValidationResult>(Microsoft.Practices.EnterpriseLibrary.Validation.Validation.Validate(foo, "Composite"));

            Assert.AreEqual(2, vrs.Count);
        }

        public class Foo
        {
            public string NullPropertyA
            {
                get { return null; }
            }

            public string NullPropertyB
            {
                get { return null; }
            }
        }

        [CompositeRulesetValidator(Ruleset="Composite", TargetRulesets="A,B")]
        public class FooWithAttributes
        {
            [NotNullValidator(Ruleset="A")]
            public string NullPropertyA
            {
                get { return null; }
            }

            [NotNullValidator(Ruleset="B")]
            public string NullPropertyB
            {
                get { return null; }
            }
        }
    }
}
